using System;
using TouchSocket.Core;
using TouchSocket.Sockets;
using TouchSocket.Rpc;
using TouchSocket.Rpc.TouchRpc;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
namespace RRQMProxy.Client
{
public interface IUpRpcServer:IRemoteServer
{
///<summary>
///获取服务器版本
///</summary>
/// <exception cref="System.TimeoutException">调用超时</exception>
/// <exception cref="TouchSocket.Rpc.RpcInvokeException">Rpc调用异常</exception>
/// <exception cref="System.Exception">其他异常</exception>
System.Int32 GetLatestVersion(IInvokeOption invokeOption = default);
///<summary>
///获取服务器版本
///</summary>
/// <exception cref="System.TimeoutException">调用超时</exception>
/// <exception cref="TouchSocket.Rpc.RpcInvokeException">Rpc调用异常</exception>
/// <exception cref="System.Exception">其他异常</exception>
Task<System.Int32> GetLatestVersionAsync(IInvokeOption invokeOption = default);

///<summary>
///获取服务端UpdateConfiguration
///</summary>
/// <exception cref="System.TimeoutException">调用超时</exception>
/// <exception cref="TouchSocket.Rpc.RpcInvokeException">Rpc调用异常</exception>
/// <exception cref="System.Exception">其他异常</exception>
Updater.Core.UpdateConfiguration GetLatestConfig(IInvokeOption invokeOption = default);
///<summary>
///获取服务端UpdateConfiguration
///</summary>
/// <exception cref="System.TimeoutException">调用超时</exception>
/// <exception cref="TouchSocket.Rpc.RpcInvokeException">Rpc调用异常</exception>
/// <exception cref="System.Exception">其他异常</exception>
Task<Updater.Core.UpdateConfiguration> GetLatestConfigAsync(IInvokeOption invokeOption = default);

///<summary>
///通知服务的检查更新
///</summary>
/// <exception cref="System.TimeoutException">调用超时</exception>
/// <exception cref="TouchSocket.Rpc.RpcInvokeException">Rpc调用异常</exception>
/// <exception cref="System.Exception">其他异常</exception>
void UpdateConfiguration(System.Collections.Generic.List<System.String> files,System.String token,IInvokeOption invokeOption = default);
///<summary>
///通知服务的检查更新
///</summary>
/// <exception cref="System.TimeoutException">调用超时</exception>
/// <exception cref="TouchSocket.Rpc.RpcInvokeException">Rpc调用异常</exception>
/// <exception cref="System.Exception">其他异常</exception>
Task UpdateConfigurationAsync(System.Collections.Generic.List<System.String> files,System.String token,IInvokeOption invokeOption = default);

}
public class UpRpcServer :IUpRpcServer
{
public UpRpcServer(IRpcClient client)
{
this.Client=client;
}
public IRpcClient Client{get;private set; }
///<summary>
///获取服务器版本
///</summary>
/// <exception cref="System.TimeoutException">调用超时</exception>
/// <exception cref="TouchSocket.Rpc.RpcInvokeException">Rpc调用异常</exception>
/// <exception cref="System.Exception">其他异常</exception>
public System.Int32 GetLatestVersion(IInvokeOption invokeOption = default)
{
if(Client==null)
{
throw new RpcException("IRpcClient为空，请先初始化或者进行赋值");
}
if (Client.TryCanInvoke?.Invoke(Client)==false)
{
throw new RpcException("Rpc无法执行。");
}
System.Int32 returnData=Client.Invoke<System.Int32>("updater.server.uprpcserver.getlatestversion",invokeOption, null);
return returnData;
}
///<summary>
///获取服务器版本
///</summary>
public Task<System.Int32> GetLatestVersionAsync(IInvokeOption invokeOption = default)
{
if(Client==null)
{
throw new RpcException("IRpcClient为空，请先初始化或者进行赋值");
}
if (Client.TryCanInvoke?.Invoke(Client)==false)
{
throw new RpcException("Rpc无法执行。");
}
return Client.InvokeAsync<System.Int32>("updater.server.uprpcserver.getlatestversion",invokeOption, null);
}

///<summary>
///获取服务端UpdateConfiguration
///</summary>
/// <exception cref="System.TimeoutException">调用超时</exception>
/// <exception cref="TouchSocket.Rpc.RpcInvokeException">Rpc调用异常</exception>
/// <exception cref="System.Exception">其他异常</exception>
public Updater.Core.UpdateConfiguration GetLatestConfig(IInvokeOption invokeOption = default)
{
if(Client==null)
{
throw new RpcException("IRpcClient为空，请先初始化或者进行赋值");
}
if (Client.TryCanInvoke?.Invoke(Client)==false)
{
throw new RpcException("Rpc无法执行。");
}
Updater.Core.UpdateConfiguration returnData=Client.Invoke<Updater.Core.UpdateConfiguration>("updater.server.uprpcserver.getlatestconfig",invokeOption, null);
return returnData;
}
///<summary>
///获取服务端UpdateConfiguration
///</summary>
public Task<Updater.Core.UpdateConfiguration> GetLatestConfigAsync(IInvokeOption invokeOption = default)
{
if(Client==null)
{
throw new RpcException("IRpcClient为空，请先初始化或者进行赋值");
}
if (Client.TryCanInvoke?.Invoke(Client)==false)
{
throw new RpcException("Rpc无法执行。");
}
return Client.InvokeAsync<Updater.Core.UpdateConfiguration>("updater.server.uprpcserver.getlatestconfig",invokeOption, null);
}

///<summary>
///通知服务的检查更新
///</summary>
/// <exception cref="System.TimeoutException">调用超时</exception>
/// <exception cref="TouchSocket.Rpc.RpcInvokeException">Rpc调用异常</exception>
/// <exception cref="System.Exception">其他异常</exception>
public void UpdateConfiguration(System.Collections.Generic.List<System.String> files,System.String token,IInvokeOption invokeOption = default)
{
if(Client==null)
{
throw new RpcException("IRpcClient为空，请先初始化或者进行赋值");
}
if (Client.TryCanInvoke?.Invoke(Client)==false)
{
throw new RpcException("Rpc无法执行。");
}
object[] parameters = new object[]{files,token};
Client.Invoke("updater.server.uprpcserver.updateconfiguration",invokeOption, parameters);
}
///<summary>
///通知服务的检查更新
///</summary>
public Task UpdateConfigurationAsync(System.Collections.Generic.List<System.String> files,System.String token,IInvokeOption invokeOption = default)
{
if(Client==null)
{
throw new RpcException("IRpcClient为空，请先初始化或者进行赋值");
}
if (Client.TryCanInvoke?.Invoke(Client)==false)
{
throw new RpcException("Rpc无法执行。");
}
object[] parameters = new object[]{files,token};
return Client.InvokeAsync("updater.server.uprpcserver.updateconfiguration",invokeOption, parameters);
}

}
public static class UpRpcServerExtensions
{
///<summary>
///获取服务器版本
///</summary>
/// <exception cref="System.TimeoutException">调用超时</exception>
/// <exception cref="TouchSocket.Rpc.RpcInvokeException">Rpc调用异常</exception>
/// <exception cref="System.Exception">其他异常</exception>
public static System.Int32 GetLatestVersion<TClient>(this TClient client,IInvokeOption invokeOption = default) where TClient:
TouchSocket.Rpc.IRpcClient{
if (client.TryCanInvoke?.Invoke(client)==false)
{
throw new RpcException("Rpc无法执行。");
}
System.Int32 returnData=client.Invoke<System.Int32>("updater.server.uprpcserver.getlatestversion",invokeOption, null);
return returnData;
}
///<summary>
///获取服务器版本
///</summary>
public static Task<System.Int32> GetLatestVersionAsync<TClient>(this TClient client,IInvokeOption invokeOption = default) where TClient:
TouchSocket.Rpc.IRpcClient{
if (client.TryCanInvoke?.Invoke(client)==false)
{
throw new RpcException("Rpc无法执行。");
}
return client.InvokeAsync<System.Int32>("updater.server.uprpcserver.getlatestversion",invokeOption, null);
}

///<summary>
///获取服务端UpdateConfiguration
///</summary>
/// <exception cref="System.TimeoutException">调用超时</exception>
/// <exception cref="TouchSocket.Rpc.RpcInvokeException">Rpc调用异常</exception>
/// <exception cref="System.Exception">其他异常</exception>
public static Updater.Core.UpdateConfiguration GetLatestConfig<TClient>(this TClient client,IInvokeOption invokeOption = default) where TClient:
TouchSocket.Rpc.IRpcClient{
if (client.TryCanInvoke?.Invoke(client)==false)
{
throw new RpcException("Rpc无法执行。");
}
Updater.Core.UpdateConfiguration returnData=client.Invoke<Updater.Core.UpdateConfiguration>("updater.server.uprpcserver.getlatestconfig",invokeOption, null);
return returnData;
}
///<summary>
///获取服务端UpdateConfiguration
///</summary>
public static Task<Updater.Core.UpdateConfiguration> GetLatestConfigAsync<TClient>(this TClient client,IInvokeOption invokeOption = default) where TClient:
TouchSocket.Rpc.IRpcClient{
if (client.TryCanInvoke?.Invoke(client)==false)
{
throw new RpcException("Rpc无法执行。");
}
return client.InvokeAsync<Updater.Core.UpdateConfiguration>("updater.server.uprpcserver.getlatestconfig",invokeOption, null);
}

///<summary>
///通知服务的检查更新
///</summary>
/// <exception cref="System.TimeoutException">调用超时</exception>
/// <exception cref="TouchSocket.Rpc.RpcInvokeException">Rpc调用异常</exception>
/// <exception cref="System.Exception">其他异常</exception>
public static void UpdateConfiguration<TClient>(this TClient client,System.Collections.Generic.List<System.String> files,System.String token,IInvokeOption invokeOption = default) where TClient:
TouchSocket.Rpc.IRpcClient{
if (client.TryCanInvoke?.Invoke(client)==false)
{
throw new RpcException("Rpc无法执行。");
}
object[] parameters = new object[]{files,token};
client.Invoke("updater.server.uprpcserver.updateconfiguration",invokeOption, parameters);
}
///<summary>
///通知服务的检查更新
///</summary>
public static Task UpdateConfigurationAsync<TClient>(this TClient client,System.Collections.Generic.List<System.String> files,System.String token,IInvokeOption invokeOption = default) where TClient:
TouchSocket.Rpc.IRpcClient{
if (client.TryCanInvoke?.Invoke(client)==false)
{
throw new RpcException("Rpc无法执行。");
}
object[] parameters = new object[]{files,token};
return client.InvokeAsync("updater.server.uprpcserver.updateconfiguration",invokeOption, parameters);
}

}
}
